<template>
  <div>

    <h1 align="center" style="margin: 30px">新建项目</h1>
    <div align="center" style="margin-bottom: 20px">
      <el-input v-model="input" placeholder="请输入项目名称" style="width: 70%"></el-input>

      <el-button type="primary" icon="el-icon-search">搜索</el-button>

      <div align="right" style="margin-top: 10px">
        <el-button @click="toAddProject()">添加项目</el-button>
      </div>

    </div>
   <el-dialog
        :visible.sync="dialogVisible1"
        title="添加项目"
        style="min-width: 1000px;"
        width="50%">
      <div >
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm" >
          <el-form-item label="项目名称" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
          </el-form-item>
          <el-form-item label="项目结构" prop="region">
            <el-select v-model="ruleForm.region" placeholder="请选择建筑结构">
              <el-option label="钢结构" value="钢结构"></el-option>
              <el-option label="钢筋混凝土结构" value="钢筋混凝土结构"></el-option>
              <el-option label="砖混结构" value="砖混结构"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="项目周期" required>
            <el-col :span="11">
              <el-form-item prop="date1">
                <el-date-picker type="date" placeholder="开工日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="line" :span="2">-</el-col>
            <el-col :span="11">
              <el-form-item prop="date2">
                <el-date-picker placeholder="竣工时间" v-model="ruleForm.date2" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item>
          <el-form-item label="基础类型" prop="type">
            <el-checkbox-group v-model="ruleForm.type">
              <el-checkbox label="独立基础" name="type"></el-checkbox>
              <el-checkbox label="筏板基础" name="type"></el-checkbox>
              <el-checkbox label="桩基" name="type"></el-checkbox>
              <el-checkbox label="石基" name="type"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="特殊资源" prop="resource">
            <el-input v-model="ruleForm.resource"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="desc">
            <el-input type="textarea" v-model="ruleForm.desc"></el-input>
          </el-form-item>
          <el-form-item style="text-align: center ">
            <el-button type="primary" @click="submitForm('ruleForm')" style="width: 40%">立即创建</el-button>
            <el-button @click="resetForm('ruleForm')" style="width: 40%">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="项目名称" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="项目结构" prop="region">
          <el-select v-model="ruleForm.region" placeholder="请选择建筑结构">
            <el-option label="钢结构" value="钢结构"></el-option>
            <el-option label="钢筋混凝土结构" value="钢筋混凝土结构"></el-option>
            <el-option label="砖混结构" value="砖混结构"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目周期" required>
          <el-col :span="11">
            <el-form-item prop="date1">
              <el-date-picker type="date" placeholder="开工日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="11">
            <el-form-item prop="date2">
              <el-date-picker placeholder="竣工时间" v-model="ruleForm.date2" style="width: 100%;"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="基础类型" prop="type">
          <el-checkbox-group v-model="ruleForm.type">
            <el-checkbox label="独立基础" name="type"></el-checkbox>
            <el-checkbox label="筏板基础" name="type"></el-checkbox>
            <el-checkbox label="桩基" name="type"></el-checkbox>
            <el-checkbox label="石基" name="type"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="特殊资源" prop="resource">
          <el-input v-model="ruleForm.resource"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="desc">
          <el-input type="textarea" v-model="ruleForm.desc"></el-input>
        </el-form-item>
        <el-form-item style="text-align: center ">
          <el-button type="primary" @click="submitForm('ruleForm')" style="width: 25%;margin-right: 50px">立即创建</el-button>
          <el-button @click="resetForm('ruleForm')" style="width: 25%">重置</el-button>
        </el-form-item>
      </el-form>
    </div>


  </div>
</template>

<script>

export default {
  name: "newProject",
  data() {
    return {
      input: '',
      dialogVisible1: false,
      ruleForm: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        type: [],
        resource: '',
        desc: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入项目名称', trigger: 'blur' },
        ],
        region: [
          { required: true, message: '请选择项目建筑结构', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择开工日期', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择竣工日期', trigger: 'change' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个基础类型', trigger: 'change' }
        ],
      }
    };
  },
  methods: {
    toAddProject(){
      this.dialogVisible1=true
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>


<style scoped>

</style>
